package com.deodar.system.service.impl;

import com.deodar.common.annotation.DataSource;
import com.deodar.common.enums.DataSourceType;
import com.deodar.system.domain.StatInfo;
import com.deodar.system.mapper.StatInfoMapper;
import com.deodar.system.service.IStatInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@DataSource(value = DataSourceType.SLAVE)
@Service
public class StatInfoServiceImpl implements IStatInfoService {
    @Resource
    private StatInfoMapper statInfoMapper;
    @Override
    public StatInfo findByPripid(String pripid) {
        StatInfo statInfo = statInfoMapper.selectByPripid(pripid);
        String holdMsg = statInfo.getHoldingsmsg();
        if ((holdMsg != null) && holdMsg.length() > 1) {	//陕西的holdmsg为01、02这种
            statInfo.setHoldingsmsg(holdMsg.substring(holdMsg.length() - 1, holdMsg.length()));
        }
        return statInfo;
    }

    @Override
    public List<StatInfo> findList(int startNd, int endNd) {
        List<StatInfo> statInfos = statInfoMapper.selectList(startNd, endNd);
        for(StatInfo info : statInfos){
            String holdMsg = info.getHoldingsmsg();
            if ((holdMsg != null) && holdMsg.length() > 1) {    //陕西的holdmsg为01、02这种
                info.setHoldingsmsg(holdMsg.substring(holdMsg.length() - 1, holdMsg.length()));
            }
        }
        return statInfos;
    }
}
